package biz.datalk.industrialland.common.log.config;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;

/**
 *
 *
 * @author tarofang@163.com
 * @date 2020-06-24
 *
 */
@ConfigurationProperties(LogProperties.PREFIX)
@Getter
@Setter
@ToString
public class LogProperties implements InitializingBean {
    public static final String PREFIX = "datalk-log";

    private boolean enable = true;

    private String logServerIp;
    /** 1: MySQL, 2: MongoDB */
    private Integer logSaveDbType = 1;
    private String serverPrivateKey;

    private Boolean defaultImplPrintLog = false;

    @Override
    public void afterPropertiesSet() throws Exception {
        if (!this.enable) {
            return;
        }
        Assert.hasText(this.logServerIp, "The 'datalk-log.log-server-ip' must not be empty");
        Assert.hasText(this.serverPrivateKey, "The 'datalk-log.server-private-key' must not be empty");
        Assert.isTrue(this.logSaveDbType == 1 || this.logSaveDbType == 2, "The 'datalk-log.log-save-db-type' must be 1 or 2");
    }
}
